
const Router = require('koa-router')


const { RegisterValidater } = require('@validator');
const { User } = require('../../models/user')
const router = new Router({
    prefix: '/v1/user'
});

router.post('/register', async (ctx) => {
    // 接收参数
    // 参数校验
    // email password1 password2 nickname
    const v = await new RegisterValidater().validate(ctx);

    const user = {
        email: v.get('body.email'),
        password: v.get('body.password2'),
        nickname: v.get('body.nickname')
    }
    const r = await User.create(user)
})

router.get('/test', (ctx, next) => {
    ctx.body = { key: 'user/test' }
})

module.exports = router;